package grammar.parser;

import semantic.parser.SemanticParser;
import word.parser.WordElement;

import java.util.ArrayList;
import java.util.List;

public abstract class GrammarParser {
    private final static List<WordElement> target = new ArrayList<>();
    private static int now = 0;
    private static int scope = 0;
    private static final SemanticParser SEMANTIC_PARSER = new SemanticParser();

    public static void initGrammarParser(List<WordElement> target) {
        GrammarParser.target.addAll(target);
    }

    public static CompUnit parser() {
        return CompUnit.buildCompUnit();
    }

    public static int getNowPosition() {
        return now;
    }

    public static WordElement getWord(int position) {
        return target.get(position);
    }

    public static WordElement getAnalyzingWord(int offset) {
        return target.get(now + offset);
    }

    public static WordElement getAnalyzingWord() {
        return target.get(now);
    }

    public static WordElement analyzeNextWord() {
        //System.out.println(target.get(now).toString(true));
        now++;
        return target.get(now - 1);
    }

    public static void addScope() {
        scope++;
    }

    public static void outScope() {
        SEMANTIC_PARSER.outScope(scope);
        scope--;
    }

    public static void outScopeWithNotUpdateSymbolTable() {
        scope--;
    }

    public static int getScope() {
        return scope;
    }

    public static SemanticParser getSemanticParser() {
        return SEMANTIC_PARSER;
    }
}
